package com.cc.micro.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cc.micro.api.model.LoanInfo;
import com.cc.micro.api.vo.MultiProduct;
import com.cc.micro.common.web.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author CC
 * time 2023-07-02
 * description
 */
@Api(tags = "理财产品服务接口")
@RestController
@RequestMapping("/product")
public class ProductController extends BaseController{
    /**
     *
     * @param pageNum  查询页码
     * @param pageSize 查询总数
     * @param type 产品类型
     * @return
     */
    @ApiOperation("按产品类型分页查询")
    @GetMapping("/type/{pageNum}/{pageSize}/{type}")
    public Result<IPage<LoanInfo>> queryPageByProductType(@PathVariable Integer pageNum,
                                                          @PathVariable Integer pageSize,
                                                          @PathVariable Integer type){
        Page<LoanInfo> loanInfoPage = new Page<>(pageNum,pageSize);
        IPage<LoanInfo> result = null;
        try {
            result = loanInfoService.pageQueryByProductType(loanInfoPage, type);
        } catch (Exception e) {
           return Result.fail(e.getMessage());
        }
        return Result.ok(result);
    }
    @ApiOperation("首页展示产品")
    @GetMapping("/index")
    public Result<MultiProduct> queryIndexPageProduct(){
        MultiProduct multiProduct = loanInfoService.queryIndexPageProduct();
        return Result.ok(multiProduct);
    }



}
